package framework.system.entity;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import framework.core.entity.BaseEntity;

/**
 * @ClassName: SysRole 
 * @Description: 系统角色
 * @author: Ching Wang
 * @date 2013-5-3 下午2:34:53 
 *
 */
@Entity
@Table(name = "sys_role")
public class SysRole extends BaseEntity {

	@Id
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid" ,strategy = "org.hibernate.id.UUIDGenerator")
	@Column(name = "id", nullable = false, length = 36)
	private String id;
	
	@Column(name = "name", nullable = false, length = 100)
	private String name;
	
	/**
	 * 创建时间
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "createDate", nullable = false, updatable = false)
	private Date createDate;
	
	/**
	 * 修改时间
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "modifyDate")
	private Date modifyDate;
	
	/**
	 * 备注信息
	 */
	@Column(name = "remark", length = 4000)
	private String remark;
	
	@ManyToMany(mappedBy = "sysRoles", targetEntity = SysUser.class, cascade = CascadeType.MERGE)
	private Set<SysUser> sysUsers;
	
	@ManyToMany(targetEntity = SysResource.class, cascade = { CascadeType.MERGE, CascadeType.REFRESH },fetch = FetchType.LAZY)
	@JoinTable(name = "sys_role_resource", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "resource_id") })
	private Set<SysResource> sysResources;

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the createDate
	 */
	public Date getCreateDate() {
		return createDate;
	}

	/**
	 * @param createDate the createDate to set
	 */
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	/**
	 * @return the modifyDate
	 */
	public Date getModifyDate() {
		return modifyDate;
	}

	/**
	 * @param modifyDate the modifyDate to set
	 */
	public void setModifyDate(Date modifyDate) {
		this.modifyDate = modifyDate;
	}

	/**
	 * @return the remark
	 */
	public String getRemark() {
		return remark;
	}

	/**
	 * @param remark the remark to set
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * @return the sysUsers
	 */
	public Set<SysUser> getSysUsers() {
		return sysUsers;
	}

	/**
	 * @param sysUsers the sysUsers to set
	 */
	public void setSysUsers(Set<SysUser> sysUsers) {
		this.sysUsers = sysUsers;
	}

	/**
	 * @return the sysResources
	 */
	public Set<SysResource> getSysResources() {
		return sysResources;
	}

	/**
	 * @param sysResources the sysResources to set
	 */
	public void setSysResources(Set<SysResource> sysResources) {
		this.sysResources = sysResources;
	}
}